package com.yc.home.cloudother.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.bean.Result;
import com.yc.entity.Classs;
import com.yc.home.cloudother.mapper.ClasssMapper;
import com.yc.home.cloudother.service.IClasssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzk
 * @since 2024-10-05
 */
@Service
public class ClasssServiceImpl extends ServiceImpl<ClasssMapper, Classs> implements IClasssService {

    @Autowired
    ClasssMapper classsMapper;

    @Override
    public Result addClass(String id, String cid, String sayname) {
        try{
            //判断有没有
            LambdaQueryWrapper<Classs> lqw = new LambdaQueryWrapper<>();
            lqw.eq(Classs::getUid, id);
            lqw.eq(Classs::getCid, cid);
            Classs classs1 = classsMapper.selectOne(lqw);
            if(classs1 != null){
                if(classs1.getStatus() == 0){
                    return new Result(0, "审核中", null);
                }
                if(classs1.getStatus() == -1){
                    return new Result(-1, "已拒绝申请", null);
                }
                if(classs1.getStatus() == 2){
                    return new Result(2 , "您的班级", null);
                }
            }
            Classs classs = new Classs();
            classs.setUid(Integer.valueOf(id));
            classs.setCid(Integer.valueOf(cid));
            classs.setSayname(sayname);
            classs.setStatus(0);
            classsMapper.insert(classs);
            return new Result(1, "申请成功，待老师审核！", null);
        }catch (Exception e){
            return new Result(0 , "连接超时，请稍后再试！", null);
        }
    }
}
